FROM cimg/node:current-browsers

USER root
ENV BROWSER='chrome'
ENV BVER='beta'

RUN echo $(whoami)
RUN echo "Installing Chrome: $BVER" \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list \
&& apt-get update \
&& echo "Installing google-chrome-$BVER from apt-get" \
&& apt-get install -y google-chrome-$BVER \
&& rm -rf /var/lib/apt/lists/* \
&& echo "Installing xvfb from apt-get" \
&& apt-get install -y xvfb

# start xvfb automatically to avoid needing to express in circle.yml
ENV DISPLAY :99
RUN printf '#!/bin/sh\nXvfb :99 -screen 0 1280x1024x24 &\nexec "$@"\n' > /tmp/entrypoint \
  && chmod +x /tmp/entrypoint \
        && sudo mv /tmp/entrypoint /docker-entrypoint.sh

# ensure that the build agent doesn't override the entrypoint
LABEL com.circleci.preserve-entrypoint=true

ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["/bin/sh"]
